const CryptoJS = require("crypto-js");

const clientConfig = {
  credential: {
    secretId: process.env.X_ESS_SECRETID,
    secretKey: process.env.X_ESS_SECRETKEY,
  },
  region: '',
  profile: {
    httpProfile: {
      endpoint: 'ess.test.ess.tencent.cn',
    },
  },
};


const uploadClientConfig = {
  credential: {
    secretId: process.env.X_ESS_SECRETID,
    secretKey: process.env.X_ESS_SECRETKEY,
  },
  region: '',
  profile: {
    httpProfile: {
      endpoint: 'file.test.ess.tencent.cn',
    },
  },
};


function sendErrorLog(params) {
  console.log(params);
}

function decrypt(encStr) {
  const key = process.env.X_ESS_CALLBACKKEY;
  const iv = key.slice(0,16);
  // const encStr = 'Y5LSJy+crYyn/e0Z5AYbX7/ILCbXmaxbXvIpW8BioIR9hBGHLh/KcDu/LNhF+2j+bFRZsG2xh3nUCYrHM3jwB4rp71Cbc0q5lgqC3TXpx4XbP/CaAl5RYJyNor8XAvxHCHGMxs1Wnge9Z1K0j9ouVlfz8zAMY9LcXBlTzea+/SiK7+V2DvpIDrCDKOr7HqHPQbUmq2tOz72y7SwV7Y10hY24jYHcOSlcVK6MpJjnXT4WXi6cmlpldjT1YAGUM0A574R3t9UAwofBWCcmIbBDcto9Wdmqc+kQFhKYUecNwp/ZKrMfwBDLkakttkqfshASz27zIkCYXosQ1xWTj5pG41w6KqLaPOeEA3RYth+43LLB4lqukXTTb2CY1P0NRnhYljaeENsi0f9feEYO5sUVW1Lb2/yKTkOjEiX2rO2IGG4LqM/1D46eFEUxGex094GkEPj/b6jueGkO+tn398wHhPd84IxkpqXDV8OVQ39mYS2A0LtZ8UxO453f620fA5fGX3xUi4OkhRAdWPDci0DACxfGJq2GL/ANBsjdA14l3zW9oJDKLKu0PqfQ4Ym+9MaNGJ+NUeXHWqN8Vn198rc8XRofFRt5qAr9sYplDEf39rq1S60IKkh/swCfcq24QFZklVhoNSKaM2NOKlzS7oG64yaBuOILcjgKpQcedv3lk5RmuKvlLPvuZhlcLkhYcXTwRB8pbMVW/Icy92Qbv4qNsk+RoWRozEUFVN5fa8kjtJZanII7tzJcBEB37Qhg8pJJs7DGNpwat/Zckz+6HMAxGVDa6zvx1Gw/dOrTc4KhUgvLuzalcvXs4AxeRLj7aDzethwoZhktWqH38oST5yk3Mgj0uAWjQl8gBswZ583sjlFtpVQ+Tvw4Yc/GgKt5KdZ/bXvtQwB2U2TNDhkuUTaN0tri/+rwQQYEJbQtAzsBmiwvMcU11G16AuhyRHojtp+5b3ngg9mkr7dwAZMAVCze1BJDLTLmWTG9IjfZ93ZFpSrwhPJVIDqy1YDAF01RGtTP6h0C1dh4TCYrdGKnBC4xHj1Sm3qpqbe1L/mxaU/aMVy1moa47Byu2fm/wRETdNfRl3n83ZHYb9sjt8ZPj5mGNOLm9ifheGkqT/nQRsdy1GxVnziXqAcd0GpevPGQOmSZ7UhkpL+h2UuKcnRs9FUideROq448TVJ13pVdl+ndnnv0c8gAhDtI7ld8XU7Uf34EQosU6XBhXdnyDs6UCN7JGg=='
  // 解密方法
 const decryptedContent = CryptoJS.AES.decrypt(
  // CryptoJS.enc.Base64.parse(encStr),
  encStr,
  CryptoJS.enc.Utf8.parse(key),
  {
    iv: CryptoJS.enc.Utf8.parse(iv),
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  }
);

return JSON.parse(decryptedContent.toString(CryptoJS.enc.Utf8))
}

module.exports = {
  clientConfig,
  uploadClientConfig,
  sendErrorLog,
  decrypt,
};

